Skip to content

Conversation

@BurnzZ
Copy link
Owner

@BurnzZ BurnzZ commented Apr 1, 2025

This is mostly just a workaround for rules_python < 1.3.0. In bazel-contrib#2539, there was a new python -m invocation style via the main_module attribute. For instance, you can directly invoke pytest in py_test via:

py_test(
    main_module = "pytest.main",
    ...
)

However, for rules_python < 1.3.0, we need something like this:

load("@rules_python//python:py_test.bzl", "py_test")

py_console_script_binary(
    name = "test",
    args = args,
    pkg = "@pypi//pytest_bazel",
    script = "pytest_bazel",
    binary_rule = py_test,
)

However, when doing bazel query 'kind("py_test", //target:test)' --output=build, the srcs attribute of py_test would only be ["//target:rules_python_entry_point_test.py"].

This breaks some of the other rules/macros that read the srcs attribute of the py_test rule, as only the entry point is exposed, not the entire srcs of test files.

@BurnzZ BurnzZ changed the title allow srcs in py_console_script_binary when using py_test as the binary allow srcs in py_console_script_binary when using py_test as the binary Apr 1, 2025
@BurnzZ BurnzZ force-pushed the py_console_script_binary-allow-srcs-for-py_test branch from 4e4153f to d609b52 Compare April 2, 2025 00:12
@BurnzZ BurnzZ force-pushed the py_console_script_binary-allow-srcs-for-py_test branch from d609b52 to 74419ae Compare April 2, 2025 00:52
@BurnzZ BurnzZ marked this pull request as draft April 2, 2025 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants